﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
using libDAL;

namespace libAddressBook.FORMS
{
    public partial class frmOperationalSettings : Telerik.WinControls.UI.RadForm
    {
        private frmAddressBook addressBook;
        private DataRow[] drSettings = { };


        public frmOperationalSettings(ref frmAddressBook addr)
        {
            InitializeComponent();
            addressBook = addr;
            
        }

        public DataRow[] getset_CurrentSelectedCompany
        {
            get
            {
                return drSettings;
            }
            set
            {
                drSettings = value;
            }
        }

        private void radButton6_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void radButton12_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void frmOperationalSettings_FormClosing(object sender, FormClosingEventArgs e)
        {
           // addressBook.getset_SelectedRowStatus = false;
        }

        private void frmOperationalSettings_Load(object sender, EventArgs e)
        {
            try
            {
                drSettings = addressBook.getset_SelectedCompanyForOperational;
                if (drSettings.Length > 0)
                {
                    set_FieldsValues();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " frmOperationalSettings_Load"); 
            }
        }

        private void set_OutHoldGrn()
        {
            try
            {
                if (chkHoldAccount.Checked == true)
                {
                    drSettings[0]["holdgrn"] = true;
                }
                else if (chkHoldAccount.Checked == false)
                {
                    drSettings[0]["holdgrn"] = false;
                }
                else
                {
                    drSettings[0]["holdgrn"] = false;
                }


                drSettings[0]["remarks"] = txtRemarks.Text.Trim();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_HoldGrn");
            }
        }

        private void set_HoldGrn()
        {
            try
            {
                if (clsGenFunction.get_checkStringNull(drSettings[0]["holdgrn"]).ToString().Trim() == "False")
                {
                    chkHoldAccount.Checked = false;
                }
                else if (clsGenFunction.get_checkStringNull(drSettings[0]["holdgrn"]).ToString().Trim() == "True")
                {
                    chkHoldAccount.Checked = true;
                }
                else
                {
                    chkHoldAccount.Checked = false;
                }

                txtRemarks.Text = clsGenFunction.get_checkStringNull(drSettings[0]["remarks"]).ToString().Trim();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_HoldGrn"); 
            }
        }

        private void set_LCLInsuranceCover()
        {
            try
            {
                if (clsGenFunction.get_checkStringNull(drSettings[0]["inscover"]).ToString().Trim() == "False")
                {
                    chkInsuranceLCL.Checked = false;
                }
                else if (clsGenFunction.get_checkStringNull(drSettings[0]["inscover"]).ToString().Trim() == "True")
                {
                    chkInsuranceLCL.Checked = true;
                }
                else
                {
                    chkInsuranceLCL.Checked = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_InsuranceCover");
            }
        }

        private void set_LCLOutInsuranceCover()
        {
            try
            {
                if (chkInsuranceLCL.Checked == false)
                {
                    drSettings[0]["inscover"] = false;
                }
                else if (chkInsuranceLCL.Checked == true)
                {
                    drSettings[0]["inscover"] = true;
                }
                else
                {
                    drSettings[0]["inscover"] = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_InsuranceCover");
            }
        }

        private void set_LCLBillAgent()
        {
            try
            {
                if (clsGenFunction.get_checkStringNull(drSettings[0]["billage"]).ToString().Trim() == "False")
                {
                    chkBillAgent.Checked = false;
                }
                else if (clsGenFunction.get_checkStringNull(drSettings[0]["billage"]).ToString().Trim() == "True")
                {
                    chkBillAgent.Checked = true;
                }
                else
                {
                    chkBillAgent.Checked = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLCashBill");
            }
        }
        
        private void set_LCLOutLBillAgent()
        {
            try
            {
                if (chkBillAgent.Checked == false)
                {
                    drSettings[0]["billage"] = false;
                }
                else if (chkBillAgent.Checked == true)
                {
                    drSettings[0]["billage"] = true;
                }
                else
                {
                    drSettings[0]["billage"] = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLCashBill");
            }
        }

        private void set_LCLBillBranch()
        {
            try
            {
                if (clsGenFunction.get_checkStringNull(drSettings[0]["billbr"]).ToString().Trim() == "False")
                {
                    chkBillBranch.Checked = false;
                }
                else if (clsGenFunction.get_checkStringNull(drSettings[0]["billbr"]).ToString().Trim() == "True")
                {
                    chkBillBranch.Checked = true;
                }
                else
                {
                    chkBillBranch.Checked = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLCashBill");
            }
        }

        private void set_LCLOutBillBranch()
        {
            try
            {
                if (chkBillBranch.Checked == false)
                {
                    drSettings[0]["billbr"] = false;
                }
                else if (chkBillBranch.Checked == true)
                {
                    drSettings[0]["billbr"] = true;
                }
                else
                {
                    drSettings[0]["billbr"] = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLCashBill");
            }
        }

        private void set_LCLCashBill()
        {
            try
            {
                if (clsGenFunction.get_checkStringNull(drSettings[0]["cashbill"]).ToString().Trim() == "False")
                {
                   chkCashBill.Checked = false;
                }
                else if (clsGenFunction.get_checkStringNull(drSettings[0]["cashbill"]).ToString().Trim() == "True")
                {
                    chkCashBill.Checked = true;
                }
                else
                {
                    chkCashBill.Checked = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLCashBill"); 
            }
        }

        private void set_LCLOutCashBill()
        {
            try
            {
                if (chkCashBill.Checked == false)
                {
                    drSettings[0]["cashbill"] = false;
                }
                else if (chkCashBill.Checked == true)
                {
                    drSettings[0]["cashbill"] = true;
                }
                else
                {
                    drSettings[0]["cashbill"] = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLCashBill");
            }
        }

        private void set_LCLMarkup()
        {
            try
            {
                 
                if (clsGenFunction.get_checkStringNull(drSettings[0]["markup"]).ToString().Trim() == "False")
                {
                   chkMarkupm3.Checked = false;
                }
                else if (clsGenFunction.get_checkStringNull(drSettings[0]["markup"]).ToString().Trim() == "True")
                {
                    chkMarkupm3.Checked = true;
                }
                else
                {
                    chkMarkupm3.Checked = false;
                }
                mskMarkupLcl.Value = clsGenFunction.get_checkComputeNullDbl(drSettings[0]["mpercent"]);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_InsuranceCover");
            }
        }

        private void set_LCLOutMarkup()
        {
            try
            {

                if (chkMarkupm3.Checked == false)
                {
                    drSettings[0]["markup"] = false;
                }
                else if (chkMarkupm3.Checked == true)
                {
                    drSettings[0]["markup"] = true;
                }
                else
                {
                    drSettings[0]["markup"] = false;
                }

                drSettings[0]["mpercent"] = mskMarkupLcl.Value;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_InsuranceCover");
            }
        }

        private void set_FCLInsuranceCover()
        {
            try
            {
                if (clsGenFunction.get_checkStringNull(drSettings[0]["fclinscover"]).ToString().Trim() == "False")
                {
                    chkInsurance.Checked = false;
                }
                else if (clsGenFunction.get_checkStringNull(drSettings[0]["fclinscover"]).ToString().Trim() == "True")
                {
                    chkInsurance.Checked = true;
                }
                else
                {
                    chkInsurance.Checked = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_InsuranceCover");
            }
        }

        private void set_FCLOutInsuranceCover()
        {
            try
            {
                if (chkInsurance.Checked == false)
                {
                    drSettings[0]["fclinscover"] = false;
                }
                else if (chkInsurance.Checked == true)
                {
                    drSettings[0]["fclinscover"] = true;
                }
                else
                {
                    drSettings[0]["fclinscover"] = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_InsuranceCover");
            }
        }

        private void set_LCLNormalBill()
        {
            try
            {
                if (clsGenFunction.get_checkStringNull(drSettings[0]["nbl"]).ToString().Trim() == "False")
                {
                    chkNormalBL.Checked = false;
                }
                else if (clsGenFunction.get_checkStringNull(drSettings[0]["nbl"]).ToString().Trim() == "True")
                {
                    chkNormalBL.Checked = true;
                }
                else
                {
                    chkNormalBL.Checked = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLCashBill");
            }
        }


        private void set_LCLOutNormalBill()
        {
            try
            {
                if (chkNormalBL.Checked == false)
                {
                    drSettings[0]["nbl"] = false;
                }
                else if (chkNormalBL.Checked == true)
                {
                    drSettings[0]["nbl"] = true;
                }
                else
                {
                    drSettings[0]["nbl"] = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLCashBill");
            }
        }

        private void set_LCLAttachmentNote()
        {
            try
            {
                if (clsGenFunction.get_checkStringNull(drSettings[0]["anote"]).ToString().Trim() == "False")
                {
                    chkAttachmentNote.Checked = false;
                }
                else if (clsGenFunction.get_checkStringNull(drSettings[0]["anote"]).ToString().Trim() == "True")
                {
                    chkAttachmentNote.Checked = true;
                }
                else
                {
                    chkAttachmentNote.Checked = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLAttachmentNote");
            }
        }

        private void set_LCLOutAttachmentNote()
        {
            try
            {
                if (chkAttachmentNote.Checked == false)
                {
                    drSettings[0]["anote"] = false;
                }
                else if (chkAttachmentNote.Checked == false)
                {
                    drSettings[0]["anote"] = true;
                }
                else
                {
                    drSettings[0]["anote"] = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLAttachmentNote");
            }
        }

        public void set_LCLInsuranceDetails()
        {
            try
            {
                mskInsuranceLCL.Value = clsGenFunction.get_checkComputeNullDbl(drSettings[0]["insper"]);
                mskNonFragileLCL.Value = clsGenFunction.get_checkComputeNullDbl(drSettings[0]["insperfra"]);
                mskMinChargeLCL.Value = clsGenFunction.get_checkComputeNullDbl(drSettings[0]["insminamt"]);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLInsuranceDetails");
            }
        }

        public void set_LCLOutInsuranceDetails()
        {
            try
            {
                drSettings[0]["insper"] = mskInsuranceLCL.Value;
                drSettings[0]["insperfra"] = mskNonFragileLCL.Value;
                drSettings[0]["insminamt"] = mskMinChargeLCL.Value;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLInsuranceDetails");
            }
        }

        public void set_FCLInsuranceDetails()
        {
            try
            {
                mskInsurance.Value = clsGenFunction.get_checkComputeNullDbl(drSettings[0]["fclinsper"]);
                mskNonFragile.Value = clsGenFunction.get_checkComputeNullDbl(drSettings[0]["fclinsperfra"]);
                mskMinCharge.Value = clsGenFunction.get_checkComputeNullDbl(drSettings[0]["fclinsminamt"]);
                mskStampDuty.Value = clsGenFunction.get_checkComputeNullDbl(drSettings[0]["fclstampduty"]);
                mskGovtCharge.Value = clsGenFunction.get_checkComputeNullDbl(drSettings[0]["fclgovtax"]);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLInsuranceDetails");
            }
        }

        public void set_FCLOutInsuranceDetails()
        {
            try
            {
                drSettings[0]["fclinsper"] = mskInsurance.Value;
                drSettings[0]["fclinsperfra"] = mskNonFragile.Value;
                drSettings[0]["fclinsminamt"] = mskMinCharge.Value;
                drSettings[0]["fclstampduty"] = mskStampDuty.Value;
                drSettings[0]["fclgovtax"] = mskGovtCharge.Value;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LCLInsuranceDetails");
            }
        }

        private void set_OutFieldsValues()
        {
            try
            {
                set_OutHoldGrn();
                set_LCLOutInsuranceCover();
                set_LCLOutMarkup();
                set_LCLOutBillBranch();
                set_LCLOutCashBill();
                set_LCLOutLBillAgent();
                set_LCLOutNormalBill();
                set_LCLOutAttachmentNote();
                set_LCLOutInsuranceDetails();

                set_FCLOutInsuranceCover();
                set_FCLOutInsuranceDetails();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_OutFieldsValues"); 
            }
        }

        private void set_FieldsValues()
        {
            try
            {
                set_HoldGrn();
                set_LCLInsuranceCover();
                set_LCLMarkup();
                set_LCLBillBranch();
                set_LCLCashBill();
                set_LCLBillAgent();
                set_LCLNormalBill();
                set_LCLAttachmentNote();
                set_LCLInsuranceDetails();


                set_FCLInsuranceCover();
                set_FCLInsuranceDetails();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_FieldsValues"); 
            }
        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            set_OutFieldsValues();
        }
    }
}
